﻿using BLL;
using gfLibrary;
using IYAKASAPortal.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;

namespace IYAKASAPortal.PrintAll
{
    public partial class PrintZJYQ : System.Web.UI.Page
    {
        private UserInfo userInfo { get; set; }
        private ReportDocument document;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] != null && Session["UserName"].ToString() != "")
            {
                string userName = Session["UserName"].ToString();
                userInfo = IYAKASAPortal.Services.UserAuthority.GetUserAuthority(userName);
            }
            else
            {
                gfJs.RunFunction(this.Page, "parent.window.location = '../logout.aspx';");
            }

            if (Request["UniqueKey"] != null && Request["UniqueKey"].ToString() != "")
            {
                BindReportData(Request["UniqueKey"].ToString());
            }
            else
            {
                gfJs.RunFunction(this.Page, "parent.window.location = '../logout.aspx';");
            }
        }

        private void BindReportData(string strKey)
        {
            RESULT_VEHICLE_INFO_BLL bll = new RESULT_VEHICLE_INFO_BLL();
            var info = bll.GetModelList("ID=" + strKey);

            if (info.Length > 0)
            {
                if (info[0].JYLBDH == "12,")
                {
                    btnRG.Visible = false;
                    btnJSDJ.Visible = true;
                }
                else
                {
                    btnJSDJ.Visible = false;
                    btnRG.Visible = true;
                }
            }

            string strPath = Server.MapPath("~/rpt/CrystalReportZJYQ.rpt");
            SetCRDataSource setData = new SetCRDataSource();
            document = setData.BindZJYQReportEx(strKey, strPath, chkSingle.Checked);
            CRZJYQ.ReportSource = document;
            CRZJYQ.DataBind();
            CRZJYQ.RefreshReport();
        }

        protected void btnYQ_Click(object sender, EventArgs e)
        {
            if (Request["UniqueKey"] != null && Request["UniqueKey"].ToString() != "")
            {
                BindReportData(Request["UniqueKey"].ToString());
            }
        }

        protected void btnZJ_Click(object sender, EventArgs e)
        {
            if (Request["UniqueKey"] != null && Request["UniqueKey"].ToString() != "")
            {
                Response.Redirect("PrintZJ_Main.aspx?UniqueKey=" + Request["UniqueKey"].ToString());
            }
            else
            {
                gfJs.RunFunction(this.Page, "parent.window.location = '../logout.aspx';");
            }
        }

        protected void btnRG_Click(object sender, EventArgs e)
        {
            if (Request["UniqueKey"] != null && Request["UniqueKey"].ToString() != "")
            {
                Response.Redirect("PrintZJRG.aspx?UniqueKey=" + Request["UniqueKey"].ToString());
            }
            else
            {
                gfJs.RunFunction(this.Page, "parent.window.location = '../logout.aspx';");
            }
        }

        protected void btnJSDJ_Click(object sender, EventArgs e)
        {
            if (Request["UniqueKey"] != null && Request["UniqueKey"].ToString() != "")
            {
                Response.Redirect("PrintZJJSDJ.aspx?UniqueKey=" + Request["UniqueKey"].ToString());
            }
            else
            {
                gfJs.RunFunction(this.Page, "parent.window.location = '../logout.aspx';");
            }
        }

        protected void chkSingle_CheckedChanged(object sender, EventArgs e)
        {
            btnYQ_Click(sender, e);
        }

        protected override void OnUnload(EventArgs e)
        {
            document.Dispose();
            base.OnUnload(e);
        }
    }
}